package com.cropdoctor.controller;

import com.cropdoctor.common.Result;
import com.cropdoctor.model.constants.PageParams;
import com.cropdoctor.model.constants.PageResult;
import com.cropdoctor.model.po.CommentPo;
import com.cropdoctor.model.vo.PublishCourseInfoVO;
import com.cropdoctor.model.vo.PublishCourseVO;
import com.cropdoctor.service.CommentService;
import com.cropdoctor.service.CourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;

    @Autowired
    CommentService commentService;

    @GetMapping("")
    @ApiOperation(value = "当用户点击课程模块 通过此接口获取所有的已发布课程")
    public Result<PageResult<PublishCourseVO>> getAll(@RequestParam(required = false,value = "mt",defaultValue = "") String mt,
                                                      @RequestParam(required = false,value = "st",defaultValue = "") String st,
                                                      @RequestParam(required = false,value = "keyword",defaultValue = "") String keyword,
                                                      @RequestParam(required = false,defaultValue = "0") int pageNo,
                                                      @RequestParam(required = false,defaultValue = "0") int pageSize){
        PageParams pageParams = new PageParams(pageNo, pageSize);
        return courseService.getCourseList(mt,st,keyword,pageParams);
    }

    @GetMapping("/info")
    public Result<PublishCourseInfoVO> getCourseInfo(@RequestParam long id){
        return commentService.getCourseWithAllComment(id);
    }

    @PostMapping("/comment")
    @ApiOperation(value = "在视频中新发表一条评论")
    public Result<Long> createComment(@RequestBody CommentPo commentPo){
        return commentService.createComment(commentPo);
    }

    @DeleteMapping("/comment/{idComment}")
    @ApiOperation(value = "根据传入的评论表主键id，删除评论")
    public Result<String> userDeleteComment(@PathVariable("idComment") long idComment){
        return commentService.userDeleteComment(idComment);
    }
}
